package com.example.secondhandspringboot.mapper;

import com.example.secondhandspringboot.domain.entity.GoodsCounted;
import com.example.secondhandspringboot.domain.entity.SearchKey;
import com.example.secondhandspringboot.domain.entity.UserBehavior;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 用户行为表 Mapper 接口
 * </p>
 *
 * @author 周在林
 * @since 2024-05-28
 */
public interface UserBehaviorMapper extends BaseMapper<UserBehavior> {

    List<GoodsCounted> countLookGoodsNums(Long currentId, int second);

    @Select("""
            select search_keyword,timestamp from user_behavior
            WHERE user_id = #{currentId} and behavior_type=1 and `timestamp` >= DATE(NOW()) - INTERVAL #{day} DAY
            """)
    List<SearchKey> getSearchKey(Long currentId, int day);

    @Select("""
            select g.category_id,count(*) as nums,max(timestamp) as last_time
            from user_behavior ub LEFT JOIN goods g\s
            on ub.goods_id=g.id
            where ub.user_id=#{currentId} and ub.behavior_type=2 and g.deleted=0 and `timestamp` >= DATE(NOW()) - INTERVAL #{day} DAY
            group BY g.category_id
            """)
    List<GoodsCounted> countCommentNums(Long currentId, int day);
}
